package org.example.controller;


import lombok.AllArgsConstructor;
import org.example.domain.po.UserTicket;
import org.example.service.IUserTicketService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yu
 * @since 2024-07-14
 */
@RestController
@AllArgsConstructor
@CrossOrigin(origins = {"*","null"})
@RequestMapping("/user-ticket")
public class UserTicketController {
    private IUserTicketService userTicketService;

    @PostMapping("/insert")
    public void insert(@RequestBody UserTicket userTicket){
        userTicketService.save(userTicket);
    }
    @GetMapping("/list1/{userId}")
    public List<UserTicket> list1(@PathVariable("userId") Integer userId){
        return userTicketService.getList1(userId);
    }
    @GetMapping("/list0/{userId}")
    public List<UserTicket> list0(@PathVariable("userId") Integer userId){
        return userTicketService.getList0(userId);
    }
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") Integer id){
        userTicketService.removeById(id);
    }
    @PutMapping("/buy/{id}")
    public void buy(@PathVariable("id") Integer id){
        userTicketService.buyById(id);
    }
}
